home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Containrs / sa / bag < prev    next >
Text File  |  1996-04-09  |  3KB  |  71 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) 1995, International Computer Science Institute
  3. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  4. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  5. -- LICENSE contained in the file: Sather/Doc/License of the
  6. -- Sather distribution. The license is also available from ICSI,
  7. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  8. --=============================================================================
  9. -- Author: Holger Klawitter
  10. -- Benedict Gomes: Extensively modified include structure, naming
  11. --                added partial class, changed subtyping
  12. -- $RO_BAG{E}     : Read-only bag
  13. -- $BAG{E}        : Bag abstraction
  14. -- BAG_INCL{E}    : Partial class for use with concrete bags
  15. -- H_BAG{E}       : Bag based on the DYNAMIC_DATA_BUCKET kernel
  16. -- BAG{E}         : Standard bag class
  17.  
  18. -- $Id: bag.sa,v 1.5 1996/04/09 10:04:46 borisv Exp $
  19. --===========================================================================
  20. abstract class $RO_BAG{E} < $CONTAINER{E}, $STR is
  21.    -- A Bag contains objects in no specified order. A Bag can
  22.    -- contain two equal objects.
  23.  
  24.    count(e:E): INT;
  25.    -- Returns the number of occurences of 'e' in the bag.
  26.     
  27.    unique!: E;
  28.    -- Yields all element from the bag, but every element will be
  29.    -- yielded not more than once.
  30.  
  31.    n_unique: INT;
  32.    -- Returns the numver of different(!) elements in the bag.
  33.  
  34.    union(b: $RO_BAG{E}): $BAG{E};
  35.    -- The union contains the elements of "self" and "b". 
  36.    -- result.count(e) = self.count(e) + b.count(e)
  37.    -- Is this a good definition? Is not symmetric with intersection
  38.    -- STL uses maximum rather than arithmetic sum
  39.    
  40.    intersection(b: $RO_BAG{E}):$BAG{E};
  41.    -- result.count(e) = minimum_of(self.count(e),b.count(e))
  42.    
  43.    is_subset(b: $RO_BAG{E}): BOOL;
  44.  
  45.    equals(b: $RO_BAG{E}): BOOL;
  46.    -- Return true if self and "b" have the same elements in the
  47.    -- same quantities
  48.    
  49. end;
  50. --==========================================================================
  51. abstract class $BAG{E} < $RO_BAG{E} is
  52.    -- A standard bag, which contains objects in no specified order, 
  53.    -- and can contain two equal objects
  54.    
  55.    insert(e:E);
  56.    -- Puts the element into the bag.
  57.     
  58.    delete(e:E);
  59.    -- Remove one occurence of the element from the bag. Does
  60.    -- nothing, if there is no such element in to bag.
  61.  
  62.    delete_all(e:E);
  63.    -- Remove all occurences of the element 'e'.
  64.  
  65.    delete_all(e:E): INT;
  66.    -- Returns the number of deleted items.
  67.     
  68.  
  69. end; -- $BAG{E}
  70. --===========================================================================
  71.